package sites.manager.admin.action;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sites.manager.common.kit.Ret;
import sites.manager.common.model.Action;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/action")
public class ActionController {

    @Resource
    private ActionService srv;

    /**
     * 进入新增界面
     *
     * @return
     */
    @RequestMapping("/enterActionAdd")
    public String enterActionAdd(Model model){
        //先获取父节点菜单
        List<Action> actionList = srv.getParentAction();
        model.addAttribute("actionList", actionList);
        return "action/respActionAdd";
    }

    @RequestMapping("/saveAction")
    @ResponseBody
    public Ret saveAction(@Validated Action action){
        return srv.saveAction(action);
    }

    @RequestMapping("/enterActionMng")
    public String enterActionMng(){
        return "action/pageActionMng";
    }

    @RequestMapping("/getAllAction")
    @ResponseBody
    public Ret getAllAction(){
        return srv.getAllAction();
    }

}
